package cfs.formbean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class DepositCheckForm extends FormBean {
	private String button = "";
	private String amount = "";

	public String getButton() {
		return button;
	}

	public void setButton(String s) {
		button = s;
	}

	public String getAmount() {
		return amount;
	}

	public void setAmount(String amount) {
		this.amount = trimAndConvert(amount, "<>\"");
	}

	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();
		if (amount == null || amount.length() == 0) {
			errors.add("Amount is required");
			return errors;
		}
		if (button == null || button.length() <= 0) {
			errors.add("Please select a user");
			return errors;
		}
		try {
			double value = Double.parseDouble(amount);
			int index = amount.lastIndexOf('.');
			if (index != -1 && amount.length() - index > 3) {
				errors.add("You can not specify more the two decimal");
			}
			
			if(value <= 0){
				errors.add("You must specify positive value");
			}
		} catch (NumberFormatException e) {
			errors.add("Amount is not an valid number");
		}
		return errors;
	}

}
